package org.zero.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Zero (cnzeropro@qq.com)
 * @date 2021/10/5 16:52
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(AlipayClient.class)
public class AlipayConfig {

    @Bean
    public AlipayClient alipayClient() throws AlipayApiException {
        com.alipay.api.AlipayConfig alipayConfig = new com.alipay.api.AlipayConfig();
        alipayConfig.setServerUrl(AlipayProperties.gatewayUrl);
        alipayConfig.setAppId(AlipayProperties.appId);
        alipayConfig.setSignType(AlipayProperties.signType);
        alipayConfig.setAlipayPublicKey(AlipayProperties.publicKey);
        alipayConfig.setPrivateKey(AlipayProperties.privateKey);
        alipayConfig.setCharset(AlipayProperties.charset);
        alipayConfig.setFormat(AlipayProperties.format);

        return new DefaultAlipayClient(alipayConfig);
    }
}
